/*
 * table_CppDefRepInfo.c
 *
 *  Created on: 2012/03/31
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"

/* KIND_DEFREPINFO		*/
typedef struct _DEFREPINFO
{
	U2		usIndex;	/* 2 */
	U2		usKind;	/* 3 */
	U2 		usPPTokenKind;	/* 2 */
	S2      sParamIndex;
	AST     astName;				/* 5 */
	AST     astLoc;					/* 6 */
} REPLISTTOKEN, *PREPLISTTOKEN;

#define TableSize  (sizeof(REPLISTTOKEN))
#define TableType  PREPLISTTOKEN
#define stTable stRepListTokenTblManager.memoryBlocks
#define maxTable stRepListTokenTblManager.maxRecordNum
#define  maxNumPerBlk  (stRepListTokenTblManager.astMaxNum_Block)

/* private field */

static TABLEMANAGER stRepListTokenTblManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};
static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stRepListTokenTblManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stRepListTokenTblManager,  resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}
static BOOL ClearTable( VOID )
{
	return Clear_Com( &stRepListTokenTblManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stRepListTokenTblManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stRepListTokenTblManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}
/* give up the way that defining get/set function pointer in the struct,
 * because of memory volume.
 */
//ACCESS_U2_FIELD index;
static U2  getIndex( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usIndex;
}
static U2  setIndex( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usIndex = value;
}
//ACCESS_U2_FIELD kind;
static U2  getKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usKind;
}
static U2  setKind( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usKind = value;
}
//ACCESS_U2_FIELD ppTokenKind;
static U2  getTokenKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usPPTokenKind;
}
static U2  setTokenKind( AST index, U2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->usPPTokenKind = value;
}
//ACCESS_S2_FIELD paramIdx;
static S2  getParamIdx( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->sParamIndex;
}
static S2  setParamIdx( AST index, S2 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->sParamIndex = value;
}
//ACCESS_IDX_FIELD location;
static AST getLocation( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLoc;
}
static AST setLocation( AST index, AST idx )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLoc = idx;
}
//ACCESS_STR_FIELD name;
static CHAR* getLabelStr( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return "";
	}
	return stCoreLabelStrAccess.getStr(pTbl->astName);
}
static AST setLabelStr( AST index, PSZ str )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astName = stCoreLabelStrAccess.addStr(str);
}
const DEFREPINFO_ACCESS stCoreDefRepInfoAccess = {
//		BOOL (*clear)( VOID );
		ClearTable,
//		BOOL (*reset)( VOID );
		ResetTable,
//		BOOL (*alloc)( AST );
		AllocTable,
//		AST  (*getMax)( VOID );
		getMaxLineNum,


//		ACCESS_U2_FIELD index;
		{
				getIndex,
				setIndex
		},
//		ACCESS_U2_FIELD kind;
		{
				getKind,
				setKind
		},
//		ACCESS_U2_FIELD ppTokenKind;
		{
				getTokenKind,
				setTokenKind
		},
//		ACCESS_S2_FIELD paramIdx;
		{
				getParamIdx,
				setParamIdx
		},
//		ACCESS_IDX_FIELD location;
		{
				getLocation,
				setLocation
		},
//		ACCESS_STR_FIELD name;
		{
				getLabelStr,
				setLabelStr
		}
};
